package com.zhou.common.model.response;

import lombok.Data;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: mrt.
 * @Description:
 * @Date:Created in 2018/1/24 18:33.
 * @Modified By:
 */
@Data
@ToString
public class QueryResult<T> {
    //数据列表
    private List<T> list;
    //数据总数
    private long total;

    public QueryResult(){}

    private QueryResult(List<T> list, long total) {
        if (list == null) {
            list = new ArrayList<>();
        }
        if (total <= 0 && total != list.size()) {
            total = list.size();
        }
        this.list = list;
        this.total = total;
    }

    public static <T> QueryResult<T> get(List<T> list, long total) {
        return new QueryResult<>(list, total);
    }
}
